########################################################################
# mainframe.py - Defines a wx.Frame derivative that contains code common
# 	to all of the frame windows used in wickddup's various modes.
#
# Created 2006.07.12 by Warren Young
#
# Copyright (c) 2006 by Pixel Corps.  This program may be used under
# the terms of the X11 license, a copy of which should have accompanied
# this program, in the LICENSE file.
########################################################################

import localparms, util, about

import wx

import os


#### class MainFrame ###################################################


class MainFrame(wx.Frame):
	""" 
	Class defining the common elements to all wickddup top-level windows.
	""" 
	def __init__(self, uploader):
		# Call parent class to initialize the frame window itself
		wx.Frame.__init__(self, None, wx.ID_ANY,
				localparms.parms.programName,
				style = wx.MINIMIZE_BOX | wx.SYSTEM_MENU |
				wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN)

		# Init member variables
		self.uploader = uploader
		
		# Add the Windows icon to the window
		if os.name in ("win", "nt"):
			try:
				import win32api
				exeName = win32api.GetModuleFileName( \
						win32api.GetModuleHandle(None))
				print exeName
				icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO)
				self.SetIcon(icon)
			except:
				print "Couldn't load icon"
			
		# Create a menu for the frame -- on OS X, this is the
		# application menu instead.
		helpMenu = wx.Menu()
		helpMenu.Append(wx.ID_ABOUT, 'About...', 'About the program')

		# Create menu bar
		menuBar = wx.MenuBar()
		menuBar.Append(helpMenu, "&Help")
		self.SetMenuBar(menuBar)

		# Bind events to handler functions
		wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout)
		wx.EVT_MENU(self, wx.ID_EXIT, self.OnExit)
		

	def OnAbout(self, e):

		# Open dialog - destroy on close
		d = about.AboutDialog(self)
		d.ShowModal()
		d.Destroy()


	def OnExit(self, e):
		print "EXIT 0"
		self.Shutdown()


	def Shutdown(self):
		print "IN SHUTDOWN"
		self.Close()

